package com.cn.wkditui;

import android.app.Activity;
import android.app.Dialog;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;



/**
 * Created by Administrator on 2016/4/22.
 */
public class Utils {

    public static void ShowDialog(Activity context,String Title, final CallBack callBack){
        final Dialog dialog = new Dialog(context, R.style.Dialog);
        View view = View.inflate(context, R.layout.view_dialog, null);
        dialog.setContentView(view);
        TextView tvcancel = (TextView) view.findViewById(R.id.tvcancel);
        TextView title = (TextView) view.findViewById(R.id.title);
        TextView tvconfirm = (TextView) view.findViewById(R.id.tvconfirm);
        title.setText(Title);
        WindowManager windowManager = context.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = (int) (display.getWidth()*0.64); //设置宽度
        lp.height = (int) (display.getHeight()*0.2); //设置高度
        dialog.getWindow().setAttributes(lp);
        tvcancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.onclickCancel(dialog);
            }
        });
        tvconfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.onclickConfirm(dialog);
            }
        });

        dialog.show();

    }

    public interface CallBack{
        void onclickConfirm(Dialog dialog);
        void onclickCancel(Dialog dialog);
    }

}
